package cn.xmkeshe.dao;

import cn.xmkeshe.model.Cars;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface ICarsDao {

//  根据车牌号查询车辆
  @Select("select * from cars where carid = #{carid}")
  public Cars findById(String carid);

  //  修改线路状态
  @Update("update cars set status = #{status} where carid = #{carid}")
  public boolean doUpdateByCarid(@Param("carid") String carid,@Param("status")int status);

  @Insert("insert into cars(carid,number,type,price,lid,fleetid) values (#{carid},#{number},#{type},#{price},#{lid},#{fleetid})")
  public boolean doCreate(Cars cars);

  @Select("SELECT cars.*,fleet.name,line.start,line.end,line.status FROM cars,fleet,line WHERE cars.fleetid = fleet.fleetid and cars.lid = line.lid LIMIT #{start},#{lineSize}")
  public List<Cars> findAllBySplit(Map<String,Object> params);

  @Select("select COUNT(carid) from cars")
  public Integer getAllCount();

//  模糊查询，根据车牌号
//  @Select("SELECT cars.*,line.start,line.end,line.status FROM cars JOIN line WHERE cars.lid = line.lid and number like #{number} LIMIT #{currentPage},#{lineSize}")
  @Select("SELECT cars.*,fleet.name,line.start,line.end,line.status FROM cars,fleet,line WHERE cars.fleetid = fleet.fleetid and cars.lid = line.lid and number like #{number} LIMIT #{currentPage},#{lineSize}")
  public List<Cars> findByNumber(@Param("currentPage") int currentPage, @Param("lineSize") int lineSize, @Param("number") String number);
}
